<template>
  <div class="content-box">
    <nav-title title="教育经历" />
    <div class="line">
      <span class="important"></span>
      <div class="label">开始时间</div>
      <div class="value">
        <group>
          <datetime value-text-align="left" readonly placeholder="请选择" v-model="edus.startDt"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">结束时间</div>
      <div class="value">
        <group>
          <datetime value-text-align="left" readonly placeholder="请选择" v-model="edus.endDt"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">学校名称</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="edus.cSchool" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">专业</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="edus.cMajor" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">学历</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="educationList" v-model="edus.cEduciton"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">学位</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="degreeList" v-model="edus.cDegree"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">是否统招</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="lcList" v-model="edus.cYesNo"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">是否最高学历</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="lcList" v-model="edus.cYesNo1"></popup-radio>
        </group>
      </div>
    </div>
    <div class="submit-btn" @click="save" v-if="showOr">
      保存
    </div>
    <div class="remove-btn" @click="remove" v-if="showOr">
      删除
    </div>
  </div>

</template>

<script>
import { Datetime, Group, Cell, PopupRadio } from "vux";
import { savePEdu, delEducation, getDicItem } from "../../../api/api";
import { json2Form } from "../../../util/http";

export default {
  name: "input-information",
  components: {
    Datetime,
    Group,
    Cell,
    PopupRadio
  },
  mounted() {
    //获取字典
    this.getDic();
    if (this.$route.params.hirdid) {
      console.log(this.$route.params.hirdid);
    }
  },
  created() {
    this.getEdus();
  },
  data() {
    return {
      edus: {
        emplid: "10070226",
        cModStauts: "",
        cTransactionNbr: ""
      },

      educationList: [],

      degreeList: [],

      lcList: [{ value: "是", key: "Y" }, { value: "否", key: "N" }],
      showOr: true
    };
  },
  methods: {
    getDic() {
      //学历字典
      getDicItem({ fileName: "C_EDUCITONs" })
        .then(res => {
          if (res && res.retCode === "000000") {
            for (let i = 0; i < res.retData.length; i++) {
              this.educationList.push({
                value: res.retData[i].xlatshortname,
                key: res.retData[i].fieldvalue
              });
            }
          }
        })
        .catch(res => {});

      //学位字典
      getDicItem({ fileName: "C_DEGREE" })
        .then(res => {
          if (res && res.retCode === "000000") {
            for (let i = 0; i < res.retData.length; i++) {
              this.degreeList.push({
                value: res.retData[i].xlatshortname,
                key: res.retData[i].fieldvalue
              });
            }
          }
        })
        .catch(res => {});
    },
    save() {
      if (this.edus.cModStauts == "U") {
        this.edus.cModStauts = "U";
      } else {
        this.edus.cModStauts = "C";
      }

      // if(this.beginDate === ''){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择开始时间'
      //   });
      //   return;
      // }

      // if(this.endDate === ''){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择结束时间'
      //   });
      //   return;
      // }

      // if(this.school === ''){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请输入学校名称'
      //   });
      //   return;
      // }

      // if(this.education.length === 0){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择学历'
      //   });
      //   return;
      // }

      // if(this.recruit.length === 0){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择是否统招'
      //   });
      //   return;
      // }

      // if(this.high.length === 0){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择是否最高学历'
      //   });
      //   return;
      // }

      console.log(this.edus);
      savePEdu(json2Form(this.edus))
        .then(res => {
          const that = this;
          //成功：000000
          if (res && res.retCode === "000000") {
            //保存成功
            // 显示
            this.$vux.alert.show({
              title: "奥克斯",
              content: "保存成功",
              onHide() {
                that.$router.push({
                  name: "userBase",
                  params: {
                    cnta: that.edus.cTransactionNbr
                  }
                });
              }
            });
          } else {
            // 显示
            this.$vux.alert.show({
              title: "提示",
              content: res.retMsg
            });
          }
        })
        .catch(res => {
          this.$vux.alert.show({
            title: "警告",
            content: "网络异常，请稍后重试"
          });
        });
    },
    remove() {
      const _this = this;
      _this.edus.cModStauts = "D";
      _this.$vux.confirm.show({
        // 组件除show外的属性
        title: "提示",
        content: "确定删除？",
        onCancel() {},
        onConfirm() {
          console.log(_this.edus);
          delEducation(json2Form(_this.edus))
            .then(res => {
              //成功：000000
              if (res && res.retCode === "000000") {
                //删除成功
                // _this.$vux.alert.show({
                //   title: "奥克斯",
                //   content: "删除成功",
                //   onHide() {
                    _this.$router.push({
                      name: "userBase",
                      params: {
                        cnta: _this.edus.cTransactionNbr
                      }
                    });
                //   }
                // });
              } else {
                // 显示
                _this.$vux.alert.show({
                  title: "提示",
                  content: res.retMsg
                });
              }
            })
            .catch(res => {
              _this.$vux.alert.show({
                title: "",
                content: "网络异常，请稍后重试"
              });
            });
        }
      });
    },
    getEdus() {
      if (this.$route.params.edult) {
        this.edus = this.$route.params.edult;
        this.edus.cTransactionNbr = this.$route.params.ctn;
        this.edus.cModStauts = this.$route.params.cModStauts;
        if (!this.$route.params.ctn) {
          this.showOr = false;
        }
      }
    }
  }
};
</script>
<style type="text/scss" lang="scss" scoped>
@import "./personstyle";
</style>
